<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <title>管理后台</title>
        <link href="/favicon.ico" type="image/x-icon" rel="shortcut icon" />
    <!--[if lt IE 8]>
    <meta http-equiv="refresh" content="0;ie.html" />
    <![endif]-->

    <link href="/public/static/admin/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="/public/static/admin/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="/public/static/admin/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/public/static/admin/css/animate.css" rel="stylesheet">
    <link href="/public/static/admin/css/style.css?v=4.0.0" rel="stylesheet">
    <link href="/public/static/admin/css/ourstyle.css?v=4.0.0" rel="stylesheet">
    <link href="/public/static/admin/css/ratuo.css" rel="stylesheet">

    <!-- 全局js -->
    <script src="/public/static/admin/js/jquery.min.js?v=2.1.4"></script>
    <script src="/public/static/admin/js/bootstrap.min.js?v=3.3.5"></script>
    <!-- 自定义js -->
    <script src="/public/static/admin/js/content.js?v=1.0.0"></script>
    <!-- jQuery Validation plugin javascript-->
    <script src="/public/static/admin/plugins/ckeditor/ckeditor.js"></script>
    <script src="/public/static/admin/plugins/ckfinder/ckfinder.js"></script>

    <!-- iCheck -->
    <script src="/public/static/admin/js/plugins/iCheck/icheck.min.js"></script>
    <script src="/public/static/admin/js/plugins/layer/layer.min.js"></script>

    <script src="/public/static/admin/js/rt_common.js?v=4.0.1"></script> 
    <script src="/public/static/admin/js/rt_post.js?v=4.0.0"></script>
    <script src="/public/static/admin/js/jquery.validate.js"></script>
    <script src="/public/static/admin/plugins/laydate/laydate.js"></script>
    <script src="/public/static/admin/js/jquery-form.js"></script>

</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>商品列表</h5>
                </div>
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-xs-12">
                            <div class="box">
                                <div class="box-header">  
                                    <div class="panel-body">
                                        <form action="" id="search-form2" class="form-inline form-horizontal" action="{:url('Goods/goodsList')}" method="get">
                                            <b>栏目：</b>
                                            <select name="sel_id" id="sel_id" class="form-control">
                                                <option value="">所有栏目</option>
                                                {volist name="article_kinds" id="article_kind"}
                                                    <option value="{$article_kind.id}" {if $sel_id == $article_kind[id]}selected=""{/if} >{$article_kind.space}{$article_kind.name}</option>
                                                {/volist}
                                            </select>
                                            <!-- <b>关键词</b>
                                            <input type="text" name="key_word" value="" placeholder="搜索词" id="input-order-id" class="form-control"> -->
                                            <button style="margin-left:30px" type="submit" id="button-filter search-order" class="btn btn-primary"><i class="fa fa-search"></i> 查询</button>

                                            <button onclick="window.location.href=location.href;" class="btn btn-primary " style="float: right;margin-left:10px;"><i class="glyphicon glyphicon-refresh"></i>刷新</button>
                                            <button type="button" onclick="openLayer('{$handle_add}','添加商品')" class="btn btn-primary pull-right"><i class="fa fa-plus"></i>添加新商品</button>
                                        </form>
                                    </div>
                                </div>
                                <div class="box-body">
                                    <div class="row">
                                        <div class="col-sm-12">

                                            <form method="post" enctype="multipart/form-data" target="_blank" id="form-order">
                                                <div class="table-responsive">
                                                    <table class="table table-bordered table-hover">
                                                        <thead>
                                                        <tr>
                                                            <th style="width: 1px;" class="text-center">
                                                                <input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);">
                                                            </th>                
                                                            <th>ID</th>
                                                            <th class="text-left">商品分类</th>

                                                            <th class="text-left">商品名称</th>
                                                        
                                                            <th>隐藏</th>

                                                            <th>排序</th>
                                                            <th>操作</th>
                                                        </tr>
                                                        </thead>
                                                        <tbody>
                                                        {if empty($goodsList)}
                                                            <tr>
                                                                <td colspan="10" align="center">暂无记录</td>
                                                            </tr>
                                                        {/if}
                                                        {volist name="goodsList" id="list"}
                                                        <?php
                                                            foreach($article_kinds as $value){
                                                                if($list['cat_id'] == $value['id']){
                                                                    $category = $value['name'];
                                                                }
                                                            }
                                                        ?>
                                                            <tr id="row_{$list.goods_id}">
                                                                <td class="text-center">
                                                                   <input type="checkbox" name="selected[]" value="6">
                                                                </td>
                                                                <td>{$list.goods_id}</td>
                                                                <td class="text-left">{$category}</td>
                                                                <td class="text-left">{$list.goods_name}{if $list[is_hot]}<span style="color:#de2828;margin-left: 5px;font-size: 12px;">爆</span>{/if}</td>

                                                                <td>                        
                                                                    <img width="20" height="20" data-num="{$list.is_hide}" class="cursor" src="/public/static/admin/images/{if $list[is_hide] == 1}yes.png{else /}cancel.png{/if}" onclick="changeOnlyVal('goods','goods_id','{$list.goods_id}','is_hide',this)"/>
                                                                </td>
                                                                
                                                                <td>                         
                                                                    <input type="text" onkeyup="this.value=this.value.replace(/[^\d]/g,'')" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onchange="updateSort('goods','goods_id','{$list.goods_id}','sort',this)" size="4" value="{$list.sort}" />
                                                                </td>                    
                                                                <td>
                                                                    <!-- <a  target="_blank" href="{:url('Home/Index/product',array('id'=>$list['goods_id']))}" data-toggle="tooltip" title="查看商品" class="btn btn-info" data-original-title="查看详情"><i class="fa fa-eye"></i></a> -->
                                                                    <a href="javascript:void(0);" onclick='openLayer("{:url('Goods/addEditGoods',array('act'=>'edit','goods_id'=>$list['goods_id'],'sel_id'=>$sel_id))}","编辑商品")' data-toggle="tooltip" title="编辑商品" class="btn btn-primary" data-original-title="编辑"><i class="fa fa-pencil"></i></a>

                                                                    <a href="javascript:void(0);" onclick="rtdel('{$list[goods_id]}','/index.php?m=Admin&c=goods&a=delGoods')" id="button-delete6" data-toggle="tooltip" title="删除商品" class="btn btn-danger" data-original-title="删除"><i class="fa fa-trash-o"></i></a>
                                                                    <a href="javascript:void(0)" data-toggle="tooltip" class="btn btn-info" data-original-title="复制商品" title="复制商品" onclick="copygoods(this,'确定复制该商品吗？',{$list.goods_id},'/index.php/Admin/Goods/goodscopy')"><i class="fa fa-copy"></i></a>
                                                                </td>
                                                                </tr>
                                                        {/volist}
                                                        </tbody>
                                                    </table>
                                                </div>
                                            </form>

                                            <div>
                                                <div style="float:left;">共{$total}条</div>
                                                <div style="float:right;" class="pages_box">{$page|raw}</div>
                                            </div>

                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<input id="handle_status" value="" hidden="hidden">


<script>
    $(document).ready(function(){
        // ajax 加载商品列表
        // ajax_get_table('search-form2',1);
    });
    function openLayer(url,name){
        parent.layer.open({
            type: 2,
            title: name,
            shade: 0.5,
            shadeClose : false,
            maxmin: true, //开启最大化最小化按钮
            area: ['70%', '80%'],
            content: url,
            end : function(){
                var handle_status = $("#handle_status").val();
                if(handle_status == '1'){
                    window.location.href = location.href;
                }
            }
        });
    }



    // ajax 抓取页面 form 为表单id  page 为当前第几页
    function ajax_get_table(form,page){
        cur_page = page; //当前页面 保存为全局变量
        var info = $('#page_info').val();
        $.ajax({
            type : "POST",
            url:"/index.php/Admin/goods/ajaxGoodsList?p="+page+"&i="+info,//+tab,
            data : $('#'+form).serialize(),// 你的formid
            success: function(data){
                $("#ajax_return").html('');
                $("#ajax_return").append(data);
            }
        });
    }

    // 点击排序
    function sort(field)
    {
        $("input[name='orderby1']").val(field);
        var v = $("input[name='orderby2']").val() == 'desc' ? 'asc' : 'desc';
        $("input[name='orderby2']").val(v);
        ajax_get_table('search-form2',cur_page);
    }


/*    function del(id){
        parent.layer.confirm('确定把该商品加入回收站吗？', function(){
            $.ajax({
                url:"/index.php?m=Admin&c=goods&a=delGoods&id="+id,
                success: function(v){
                    var v =  eval('('+v+')');
                    parent.layer.msg(v.msg, {time: 1000});
                    if(v.hasOwnProperty('status') && (v.status == 1))
                        ajax_get_table('search-form2',cur_page);
                }
            });
        });
    }*/

function copygoods(obj,name,id,url) {
    top.layer.confirm(name,{
        icon : 3,
        btn:['确定','取消'],
    } , function(){
        $.ajax({
            url : url,
            type : "post",
            data : {good_id:id,act:'copy'},
            dataType : "json",
            success:function(data){
                if (data.status == 0) { 
                    top.layer.msg(data.message,{icon:2});
                } else {
                    top.layer.msg(data.message,{icon:1,time:1000},function(){
                        window.location.href = location.href;
                    });
                }
            }
        });
    } , function(){
        layer.close(); //再执行关闭 
    })
}


</script>

</body>

</html>